package com.gyaruo;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;

import com.gyaruo.R.id;

public class HelloWorldActivity extends Activity {
	private int imageId  = -1;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button button1 = (Button)findViewById(id.button1);
        button1.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(HelloWorldActivity.this,SecondActivity.class);
				startActivity(intent);

			}
		});
        
        Button locationPageButton = (Button)findViewById(id.locationPageButton);
        locationPageButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(HelloWorldActivity.this,LocationActivity.class);
				startActivity(intent);
			}
		});

        Button imageChangeButton = (Button) findViewById(id.imageChangeButton);
        imageChangeButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ImageView image = (ImageView) findViewById(R.id.imageView1);
				RotateAnimation rotate = new RotateAnimation(0, 360, 
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
				rotate.setDuration(1000);
				//rotate.setFillBefore(true);
				AlphaAnimation alpha = new AlphaAnimation(1, 0.1f);
				//alpha.setDuration(1000);
				
				//rotate.setStartTime(AnimationUtils.currentAnimationTimeMillis());
				
				AnimationSet set = new AnimationSet(true);
				set.addAnimation(rotate);
				set.addAnimation(alpha);
				set.setDuration(1000);
				//image.setAnimation(set);
				//image.invalidate();
				image.startAnimation(set);
				
				// TODO 暫定
				if(imageId != R.drawable.ooisi_madoka){
					imageId = R.drawable.ooisi_madoka;
				}else {
					imageId = R.drawable.madomagi;
				}
				
				Bitmap afterImage = BitmapFactory.decodeResource(getResources(), imageId);
				image.setImageBitmap(afterImage);
			}
		});
    }
}